package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/user/order")
public class UserOrderController {

    @Autowired
    private OrderService orderService;

//    催单
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        orderService.reminder(id);
        return Result.success("您的催单信息已发送");
    }

//    再来一单
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id){
        orderService.repetition(id);
        return Result.success();
    }

//    历史订单查询
    @GetMapping("/historyOrders")
    public Result<PageResult> getHistoryOrders(OrdersPageQueryDTO dto){
        log.info("分页查询，参数：{}}", dto);
        PageResult pageinfo = orderService.userpage(dto);
        return Result.success(pageinfo);
    }

//    取消订单
    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable Long id) throws Exception {
        orderService.cancel(id);
        return Result.success();
    }

//    查询订单详情
    @GetMapping("/orderDetail/{id}")
    public Result seleteOrderAll(@PathVariable Long id){
        OrderVO vo = orderService.seleteOrderAll(id);
        return Result.success(vo);
    }

//    用户下单
    @PostMapping("/submit")
    public Result<OrderSubmitVO> Order(@RequestBody OrdersSubmitDTO dto){
        OrderSubmitVO vo =  orderService.Order(dto);
        return Result.success(vo);

    }

//    订单支付
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO dto)throws Exception {
        log.info("订单支付：{}", dto);
        OrderPaymentVO orderPaymentVO = orderService.payment(dto);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }


}
